#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.enums.service;

import com.google.common.base.Strings;
import ${package}.utils.SpringContextUtil;

import java.util.Objects;

public interface BeanNameEnumsService extends EnumsBaseService{
    /**
     * 获取bean名称
     * @return
     */
    String getBeanName();

    /**
     * 根据code获取bean
     * @param clazz
     * @param code
     * @param enumClass
     * @return
     * @param <T>
     * @param <E>
     */
    default <T, E extends Enum<E> & BeanNameEnumsService> T getBean(Class<T> clazz, String code, Class<E> enumClass) {
        E enumByCode = EnumsBaseService.getEnumByCode(code, enumClass);
        if(Objects.isNull(enumByCode)){
            return null;
        }
        if(Strings.isNullOrEmpty(enumByCode.getBeanName())){
            return null;
        }
        return SpringContextUtil.getBean(clazz, enumByCode.getBeanName());
    }
}
